package utils.adapter;

import android.content.Context;
import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.myapplication.R;

import java.util.List;
import java.util.zip.Inflater;

import entity.AlbumpageRecomResult;
import tools.ItemOnClickListener;

import utils.texttools.StringUtil;
import volley.VolleySingleton;

/**
 * Created by dllo on 15/12/5.
 */
public class AlbumRecomAdapter extends BaseAdapter {
    private List<AlbumpageRecomResult.ListEntity> listEntity;
    private LayoutInflater inflater ;

    public AlbumRecomAdapter(Context context) {
        this.inflater = LayoutInflater.from(context);
    }

    public void addData(List<AlbumpageRecomResult.ListEntity> datas) {
        listEntity = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (listEntity != null) {
            Log.d("AlbumRecomAdapter", "listEntity.size():" + listEntity.size());
            return listEntity.size();

        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder= new ViewHolder();
        convertView = inflater.inflate(R.layout.albumpage_recomtab_fragment_item,null);
        holder.albumRecom_title = (TextView)convertView.findViewById(R.id.albumpage_recomtab_title);
        holder.albumRecom_minTitle = (TextView)convertView.findViewById(R.id.albumpage_recomtab_MinTitle);
        holder.albumRecom_tracksCounts = (TextView)convertView.findViewById(R.id.albumpage_recomtab_TracksCounts);
        holder.albumRecom_playsCounts = (TextView) convertView.findViewById(R.id.albumpage_recomtab_PlaysCounts);
        holder.albumRecom_img = (NetworkImageView)convertView.findViewById(R.id.albumpage_recomtab_img);

        if (listEntity != null) {
        holder.albumRecom_title.setText(listEntity.get(position).getTitle());
        holder.albumRecom_minTitle.setText(listEntity.get(position).getIntro());
        holder.albumRecom_playsCounts.setText(StringUtil.longToWan(listEntity.get(position).getPlaysCounts()));
        holder.albumRecom_tracksCounts.setText(listEntity.get(position).getTracksCounts() + "集");
        VolleySingleton.getInstance().getBitmap(
                listEntity.get(position).getCoverMiddle(),holder.albumRecom_img);
        }
        return convertView;
    }



    public class ViewHolder{
     private NetworkImageView albumRecom_img;
        private TextView albumRecom_title,albumRecom_minTitle,albumRecom_playsCounts,
        albumRecom_tracksCounts;

    }
}
